/*
 * Created on 05/12/2012 - 11:30 AM
 */
package dxfpresentation;

import java.util.ArrayList;
import java.util.List;
import sembr.entities.Field;

/**
 *
 * @author adriano
 */
public class PostProcessingReport extends javax.swing.JDialog {

    /**
     * Creates new form PostProcessingReport
     */
    public PostProcessingReport(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();  
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlPostProcessingReport = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstPostProcessingReports = new javax.swing.JList();
        pnlFieldProperties = new javax.swing.JPanel();
        cmbFieldType = new javax.swing.JComboBox();
        lblFieldType = new javax.swing.JLabel();
        lblFieldDirection = new javax.swing.JLabel();
        cmbFieldDirection = new javax.swing.JComboBox();
        txtXfField = new javax.swing.JTextField();
        txtXiField = new javax.swing.JTextField();
        lblXiField = new javax.swing.JLabel();
        lblXfField = new javax.swing.JLabel();
        lblYfField = new javax.swing.JLabel();
        txtYfField = new javax.swing.JTextField();
        txtYiField = new javax.swing.JTextField();
        lblYiField = new javax.swing.JLabel();
        lblZiField = new javax.swing.JLabel();
        txtZiField = new javax.swing.JTextField();
        lblZfField = new javax.swing.JLabel();
        txtZfField = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        btnInsertPostProcessing = new javax.swing.JButton();
        btnCancelPostProcessing = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(438, 450));
        setResizable(false);

        pnlPostProcessingReport.setBorder(javax.swing.BorderFactory.createTitledBorder("Relatórios de Pós-Processamento"));

        lstPostProcessingReports.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Filme 2D", "Filme 3D", "Distribuição de Campo em determinado tempo" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(lstPostProcessingReports);

        javax.swing.GroupLayout pnlPostProcessingReportLayout = new javax.swing.GroupLayout(pnlPostProcessingReport);
        pnlPostProcessingReport.setLayout(pnlPostProcessingReportLayout);
        pnlPostProcessingReportLayout.setHorizontalGroup(
            pnlPostProcessingReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPostProcessingReportLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlPostProcessingReportLayout.setVerticalGroup(
            pnlPostProcessingReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPostProcessingReportLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                .addContainerGap())
        );

        pnlFieldProperties.setBorder(javax.swing.BorderFactory.createTitledBorder("Propriedades de Campo"));

        cmbFieldType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Elétrico", "Magnético" }));

        lblFieldType.setText("Tipo:");

        lblFieldDirection.setText("Direção:");

        cmbFieldDirection.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "x", "y", "z" }));

        txtXfField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtXfField.setText("0.00");

        txtXiField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtXiField.setText("0.00");

        lblXiField.setText("xi:");

        lblXfField.setText("xf:");

        lblYfField.setText("yf:");

        txtYfField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtYfField.setText("0.00");

        txtYiField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtYiField.setText("0.00");

        lblYiField.setText("yi:");

        lblZiField.setText("zi:");

        txtZiField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtZiField.setText("0.00");

        lblZfField.setText("zf:");

        txtZfField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtZfField.setText("0.00");

        javax.swing.GroupLayout pnlFieldPropertiesLayout = new javax.swing.GroupLayout(pnlFieldProperties);
        pnlFieldProperties.setLayout(pnlFieldPropertiesLayout);
        pnlFieldPropertiesLayout.setHorizontalGroup(
            pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblYiField)
                    .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                            .addComponent(lblZiField)
                            .addGap(4, 4, 4)
                            .addComponent(txtZiField))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlFieldPropertiesLayout.createSequentialGroup()
                            .addComponent(lblXiField)
                            .addGap(3, 3, 3)
                            .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtXiField)
                                .addComponent(txtYiField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(52, 52, 52)
                .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblYfField)
                            .addComponent(lblZfField, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(5, 5, 5)
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtYfField)
                            .addComponent(txtZfField)))
                    .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                        .addComponent(lblXfField)
                        .addGap(3, 3, 3)
                        .addComponent(txtXfField, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(75, 75, 75))
            .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(lblFieldType)
                .addGap(3, 3, 3)
                .addComponent(cmbFieldType, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lblFieldDirection)
                .addGap(2, 2, 2)
                .addComponent(cmbFieldDirection, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlFieldPropertiesLayout.setVerticalGroup(
            pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlFieldPropertiesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbFieldType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFieldType)
                    .addComponent(lblFieldDirection)
                    .addComponent(cmbFieldDirection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblXfField)
                            .addComponent(txtXfField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtYfField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblYfField))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblZfField)
                            .addComponent(txtZfField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlFieldPropertiesLayout.createSequentialGroup()
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtXiField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblXiField))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtYiField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblYiField))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFieldPropertiesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtZiField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblZiField))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        btnInsertPostProcessing.setText("Inserir");
        btnInsertPostProcessing.setMaximumSize(new java.awt.Dimension(72, 20));
        btnInsertPostProcessing.setMinimumSize(new java.awt.Dimension(72, 20));
        btnInsertPostProcessing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertPostProcessingActionPerformed(evt);
            }
        });

        btnCancelPostProcessing.setText("Cancelar");
        btnCancelPostProcessing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelPostProcessingActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnCancelPostProcessing)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnInsertPostProcessing, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInsertPostProcessing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelPostProcessing))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlPostProcessingReport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlFieldProperties, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlPostProcessingReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlFieldProperties, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * Close Post Processing Report jDialog
     * @param evt 
     */
    private void btnCancelPostProcessingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelPostProcessingActionPerformed
        
        this.dispose();
    }//GEN-LAST:event_btnCancelPostProcessingActionPerformed

    private void btnInsertPostProcessingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertPostProcessingActionPerformed
    
       selectedReports = new ArrayList<String>();
       
       for (int i = 0; i < lstPostProcessingReports.getSelectedValuesList().size(); i++)
       {
           selectedReports.add(lstPostProcessingReports.getSelectedValuesList().get(i).toString());
       }
       
       this.dispose();
    }//GEN-LAST:event_btnInsertPostProcessingActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PostProcessingReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PostProcessingReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PostProcessingReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PostProcessingReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                PostProcessingReport dialog = new PostProcessingReport(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    private Field field;
    List<String> selectedReports;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelPostProcessing;
    private javax.swing.JButton btnInsertPostProcessing;
    private javax.swing.JComboBox cmbFieldDirection;
    private javax.swing.JComboBox cmbFieldType;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblFieldDirection;
    private javax.swing.JLabel lblFieldType;
    private javax.swing.JLabel lblXfField;
    private javax.swing.JLabel lblXiField;
    private javax.swing.JLabel lblYfField;
    private javax.swing.JLabel lblYiField;
    private javax.swing.JLabel lblZfField;
    private javax.swing.JLabel lblZiField;
    private javax.swing.JList lstPostProcessingReports;
    private javax.swing.JPanel pnlFieldProperties;
    private javax.swing.JPanel pnlPostProcessingReport;
    private javax.swing.JTextField txtXfField;
    private javax.swing.JTextField txtXiField;
    private javax.swing.JTextField txtYfField;
    private javax.swing.JTextField txtYiField;
    private javax.swing.JTextField txtZfField;
    private javax.swing.JTextField txtZiField;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the field
     */
    public Field getField() 
    {
        return field;
    }

    /**
     * Populates components at Post Processing Report based on field parameter
     * @param field the field to set
     */
    public void setField(Field field) 
    {
        this.field = field;
        
        if (field.getFieldType().equals("Elétrico"))
        {
            cmbFieldType.setSelectedIndex(0);
        }
        else
        {
            cmbFieldType.setSelectedIndex(1);
        }
        
        if (field.getDirection().equals("x"))
        {
            cmbFieldDirection.setSelectedIndex(0);
        }
        else if (field.getDirection().equals("y"))
        {
            cmbFieldDirection.setSelectedIndex(1);
        }
        else
        {
            cmbFieldDirection.setSelectedIndex(2);
        }
        
        txtXiField.setText(String.valueOf(field.getInitialPosition()[0]));
        txtYiField.setText(String.valueOf(field.getInitialPosition()[1]));
        txtZiField.setText(String.valueOf(field.getInitialPosition()[2]));
    
        txtXfField.setText(String.valueOf(field.getFinalPosition()[0]));
        txtYfField.setText(String.valueOf(field.getFinalPosition()[1]));
        txtZfField.setText(String.valueOf(field.getFinalPosition()[2]));
    }
    
    public List<String> getReports() 
    {
        return selectedReports;
    }
}
